﻿function OuNode() {
    var ID;
    var Name;
}
//选人参数说明
//rootPath:网站根路径（最后带“/”）；
//viewStyle:选人视图风格："1"：可拖拽；"2"：经典
//selectMode:选择方式："1"：单选；"2"：多选（选择后追加）；"3"：多选（选择后替换原已选择）
//selectTarget:选择目标："1"：全部；"2"：只选择内部组织机构；"3"：只选择外部组织机构
//selectOuType:选择节点类型："1"：公司；"2"：部门；"3"：员工
//textId:存放名称（以逗号隔开）的控件ID；如果有初始选择，必须在加载时赋值
//valueId:存放标识（以逗号隔开）的控件ID；如果有初始选择，必须在加载时赋值
function SelectOu(rootPath, viewStyle, selectMode,selectTarget,selectOuType, textId, valueId) {
    var ouData = new Array();
    var vlist = document.getElementById(valueId).value;
    var vlistName = document.getElementById(textId).value;
    if (vlist != null && vlist != "") {
        var vlists = vlist.split(",");
        var vlistNames = vlistName.split(",");
        for (var i = 0; i < vlists.length; i++) {
            ouData[i] = new OuNode();
            ouData[i].ID = vlists[i];
            ouData[i].Name = vlistNames[i];
        }
    }
    var url = rootPath + 'Apply/SelectOu';
    var width = 0;
    var height = 0;
    if (viewStyle == '1') {
        url += "1";
        width = 800;
        height = 500;
    }
    else {
        url += "2";
        width = 600;
        height = 500;
    }
    url += '.aspx?SelectMode=' + selectMode + '&SelectTarget=' + selectTarget + '&SelectNodeType=' + selectOuType + '&randId=' + escape(new Date());
    var retValue = window.showModalDialog(url, ouData, 'scroll:0;status:0;help:1;resizable:0;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px');
    if (typeof (retValue) != "undefined" && retValue != null) {
        var ValueList = "";
        var TextList = "";
        for (var i = 0; i < retValue.length; i++) {
            if (retValue[i].ID != null && (retValue[i].ID + "") != "") {
                if (ValueList != "") {
                    ValueList += ",";
                    TextList += ",";
                }
                ValueList += retValue[i].ID;
                TextList += retValue[i].Name;
            }
        }
        if (selectMode == '2') {
            if (vlist != "") {
                vlist += ",";
                vlistName += ",";
            }
            document.getElementById(valueId).value = vlist + ValueList;
            document.getElementById(textId).value = vlistName + TextList;
        }
        else {
            document.getElementById(valueId).value = ValueList;
            document.getElementById(textId).value = TextList;
        }
        return true;
    }
    return false;
}
